﻿using System.Text;

namespace ExtjsDocsParser
{
    internal class SharpBuilder
    {
        private readonly StringBuilder sb = new StringBuilder();
        private string indent = IndentSpace;
        private bool atNewLine = true;
        private int nodeLevel;

        const string IndentSpace = "    ";

        private void IncreaseIndent()
        {
            indent += IndentSpace;
        }

        private void NewLine()
        {
            sb.AppendLine("");
            atNewLine = true;
        }

        private void DecreaseIndent()
        {
            indent = indent.Substring(0, indent.Length - IndentSpace.Length);
        }

        void Put(string value)
        {
            if (atNewLine)
            {
                sb.Append(indent);
                atNewLine = false;
            }
            sb.Append(value);
        }

        public void StartInterface(string name)
        {
            Put("public interface ");
            Put(name);
            NewLine();
            Put("{");
            IncreaseIndent();
            NewLine();
	    }

        public void EndInterface()
        {
            DecreaseIndent();
            NewLine();
            Put("}");
            NewLine();
        }

        public string Result()
        {
            return sb.ToString();
        }

        public void StartMethod(string methodName, string returns)
        {
            Put(returns);
            Put(" ");
            Put(methodName);
            Put("(");
            IncreaseIndent();
            NewLine();
        }

        public void EndMethod()
        {
            DecreaseIndent();
            NewLine();
            Put(");");
            NewLine();
        }

        public void AddParam(string name)
        {
            Put(name);
            Put(",");
        }
    }
}